package com.contract.controller;

import com.contract.pojo.output.CarouselOutput;
import com.contract.pojo.output.JsonResult;
import com.contract.pojo.output.StatisticsOutput;
import com.contract.service.HomeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 首页controller
 *
 * @author liw
 * @version 1.0
 * @date 2022/8/13 11:10
 */
@ApiOperation("首页")
@RestController
@RequestMapping("contract/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @GetMapping("statistics")
    @ApiOperation("统计")
    @PreAuthorize("hasAuthority('home_statistics')")
    public JsonResult<StatisticsOutput> statistics() {
        return homeService.statistics();
    }

    @GetMapping("carousel")
    @ApiOperation("轮播图")
    @PreAuthorize("hasAuthority('home_carousel')")
    public JsonResult<List<CarouselOutput>> carousel() {
        return homeService.carousel();
    }

    @GetMapping("chart")
    @ApiOperation("柱状图")
    @PreAuthorize("hasAuthority('home_chart')")
    public JsonResult<Map<String, Long>> chart() {
        return homeService.chart();
    }

}
